package com.oa.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.GsonBuilder;
import com.oa.bean.Schedules;
import com.oa.biz.impl.SchedulesServiceImpl;

@WebServlet("/UserSchedules")
public class UserSchedulesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 解码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		//前台用户名
		String userName=request.getParameter("userName");
		List<Schedules> schs=new SchedulesServiceImpl().getUserSchedules(userName);
		for (Schedules s : schs) {
			System.out.println(s.getBeginTime());
		}
		response.getWriter().write(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(schs));
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
